﻿@using PNProject
@using PNProject.Core
@model PNProject.Models.ProductDetailModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout2.cshtml";
    var i = 0;
    string caname = ViewData["caname"].ToString();
    int caid = (int)ViewData["caid"];
}
<input id="caname" value="@caname" type="hidden" />
<input id="caid" value="@caid.ToString()" type="hidden" />
<input id="proname" value="@Model.Product.Name" type="hidden" />
<script type="text/javascript" src="@Url.Content("~/Scripts/script.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/main-jquery.js")"></script>
<div class="content">
    <div class="ulink">
        <ul>
            <li id="ulink_home"><a href="/"></a></li>
            <li><p>&raquo;</p></li>
            <li id="ulink_child"><a href="#"></a></li>
        </ul>
    </div>
    <div class="titlesub">
        <p>@Model.Product.Name</p>
        @*<p>Hệ thống quản lý trạm kinh doanh xăng dầu</p>*@
    </div>
    <div class="maincontent">
        <div class="leftcontent">
            <div class="menuLeft">
                <ul id="submenuContent" class="submenuContent">
                    @foreach (var sub in Model.SubMenu)
                    {
                        var id = sub.CMenuID;
                        var idhid = "hid_" + sub.CMenuID;
                        //var content = Html.Raw(sub.CContent);
                        var content = sub.CContent;
                        var liId = "li_" + id;
                        if (i == 0)
                        {
                            <li id="@liId" itemid="@id" class="active"><a id="@id" href="javascroipt:void(0);"
                                                                          onclick="addContent(this);return false;">@sub.Name</a>
                                <input id="@idhid" type="hidden" value="@content"/></li>
                        }
                        else
                        {
                            <li id="@liId" itemid="@id"><a id="@id" href="javascroipt:void(0);"
                                                           onclick="addContent(this);return false;">@sub.Name</a>
                                <input id="@idhid" type="hidden" value="@content"/></li>
                        }
                        i++;
                    }

                </ul>
            </div>
            <div class="boxleft-1">
                <div class="ttboxleft">
                    <p>Sản phẩm liên quan</p>
                </div>
                <div class="ccboxleft-1">
                    <div class="splq">
                        <ul>
                            @foreach (var item in Model.RelateProducts)
                            {
                                <li class="splq-1"><a href="@Url.Action("Index", "ProductDetails", new { CatelogId = @item.CategoryID, id = @item.ProductID })">@item.Name</a></li>
                                <li class="splq-2">
                                    <table cellspacing="0" cellpadding="0" width="100%">
                                        <tbody>
                                            <tr>
                                                <td class="pic_4">
                                                    <a href="@Url.Action("Index", "ProductDetails", new { CatelogId = @item.CategoryID, id = @item.ProductID })">
                                                        <img src="@item.Avatar" alt="" /></a>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </li>
                                <li class="splq-3"><a href="@Url.Action("Index", "ProductDetails", new { CatelogId = @item.CategoryID, id = @item.ProductID })">chi tiết</a></li>
                            }

                        </ul>
                    </div>
                </div>
            </div>
            <div class="boxleft-1">
                <div class="ttboxleft">
                    <p>Thống kê truy cập</p>
                </div>
                <div class="ccboxleft">
                    <div class="thongketruycap">
                        <ul>
                            <li>
                                <p>Hôm nay</p>
                                <span style="color: #8c060b;">@Model.VisitModel.Today</span>
                            </li>
                            <li>
                                <p>Tháng này</p>
                                <span style="color: #0000ff;">@Model.VisitModel.Month</span>
                            </li>
                            <li>
                                <p>Tổng cộng</p>
                                <span style="color: #ff0000;">@Model.VisitModel.Total</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="rightcontent">
            <div class="prodetail">
                <div class="chitietsanpham">
                    <div class="hinhsanpham">
                        <div id="lofslidecontent45">
                            <div class="lof-main-outer">
                                <ul class="lof-main-wapper">
                                    @if(!string.IsNullOrEmpty(Model.Product.Images))
                                    {
                                        var urls = ServerHelper.SplitFileName(Model.Product.Images);
                                        foreach (var url in urls)
                                        {
                                            <li>
                                                <table cellspacing="0" cellpadding="0" width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td class="pic_3">
                                                                <a href="#">
                                                                    <img src="@url" alt="" /></a>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </li>
                                        }
                                    }
                                    else
                                    {
                                        <li>
                                            <table cellspacing="0" cellpadding="0" width="100%">
                                                <tbody>
                                                    <tr>
                                                        <td class="pic_3">
                                                            <a href="#">
                                                                <img src="@Model.Product.Avatar" alt="" /></a>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </li>
                                    }


                                </ul>
                            </div>
                            <div class="lof-navigator-wapper">
                                <div onclick="return false" class="lof-next"><a href="#"></a></div>
                                <div onclick="return false" class="lof-previous"><a href="#"></a></div>
                                <div class="lof-navigator-outer">
                                    <ul class="lof-navigator">
                                        @{
                                            if (!string.IsNullOrEmpty(Model.Product.Images))
                                            {
                                                var urls = ServerHelper.SplitFileName(Model.Product.Images);
                                                foreach (var url in urls)
                                                {
                                                    <li>

                                                        <img src='@url' alt="" />

                                                    </li>
                                                }
                                            }
                                        }
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="thongtinsp">
                        @Html.Raw(@Model.Product.ShortDesc)
                    </div>
                </div>

                <div class="danhgia">
                    <span id="contentSubmenu">
                    
                    </span>
                </div>
                <div class="danhgia">
                    @Html.Partial("DetailComment",Model.CommentModels)
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dialog-confirm" title="Thông báo">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Vui lòng đăng nhập. Nếu bạn chưa là thành viên thì có thể đăng ký</p>
</div>
<script type="text/javascript">
    $(document).ready(function() {
      
        $("#sumbitComment").click(function() {

            var content = $("#commentContent").val();
            if (content == '') {
                alert("Vui lòng nhập nội dung");
                return false;
            }
            var option = {
                id: '@Model.Product.ProductID',
                mess: $.trim(content)
            };

            $.ajax({
                cache: false,
                type: "POST",
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(option),
                url: '@(Url.Action("SubmitComment", "ProductDetails"))',
                success: function (result) {
                    if (result.retult == true) {
                        window.location = location.href;
                    } else {
                        alert("Xin vui long dang nhap");
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(thrownError);
                }
            });
        });
        addContentToDiv();

        $(".titlesub p").empty();
        var lang = document.URL.indexOf("en-US") < 0 ? true : false;
        var langtext = "";
        if (lang) {
            $(".titlesub p").append("Sản phẩm - Dịch vụ");
            $("#ulink_home a").append("Trang chủ");
            $("#ulink_child a").append("Sản phẩm & Dịch vụ");
            $("#ulink_child a").attr("href", "/products");
        }
        else {
            $(".titlesub p").append("Products & Services");
            $("#ulink_home a").append("Home");
            $("#ulink_home a").attr("href", "/en-US/home");
            $("#ulink_child a").append("Products & Services");
            $("#ulink_child a").attr("href", "/en-US/products");
            langtext = "/en-US";
        }

        var caname = $("#caname").val();
        var caid = $("#caid").val();
        var proname = $("#proname").val();
        if (caname != "") {
            $(".titlesub p").empty();
            $(".titlesub p").append(proname);
            var url = langtext + "/products/index/" + caid;
            $(".ulink ul").append("<li><p>&raquo;</p></li>");
            $(".ulink ul").append("<li><a href=" + url + ">" + caname + "</a></li>");
        }

        $("#dialog-confirm").dialog({autoOpen: false,
                height: 150,
                width: 300,
                modal: true,
                buttons: {
                    "Đăng nhập": function () {
                        window.location.href = '@Url.Action("Login","Member")';
                     },
                    "Đăng ký": function () {
                        window.location.href = '@Url.Action("Register","Member")';
                    },
                    "Tiếp tục": function () {
                        $(this).dialog("close");
                    }
                }
        });
        ShowPopupLogin();
    });
    
    function ShowPopupLogin() {
        var val = '@Model.TimeView';
        if (parseInt(val) == 1) {
            $("#dialog-confirm").dialog("open");
            //alert("Please login of signup");
        }
    }
    function addContentToDiv() {
        $('.submenuContent').find('li').each(function () {
            if ($(this).hasClass('active')) {
                var id = $(this).attr("itemid");
                var hidinput = $("#hid_" + id).val();
                $("#contentSubmenu").html(hidinput);
                var liId = "li_" + id;
                LogContent($("#" + liId).text());
            }
        });
        //if ($('ul.submenuContent li').hasClass('active')) {
        //    var id = $(this).attr("itemid");
        //    var hidinput = $("#hid_" + id).val();
        //    $("#contentSubmenu").html(hidinput);
        //}
    }
    function addContent(seft) {
        $('#submenuContent').find('li').removeClass('active');
        var id = seft.id;
        var hidinput = $("#hid_" + id).val();
        $("#contentSubmenu").html(hidinput);
        var liId = "li_" + id;
        $("#" + liId).addClass("active");
        $(document).scrollTop($(document).height() / 3);
        LogContent($("#" + liId).text());
    }
    function LogContent(hid) {
        var option = {
            mess: $.trim(hid)
         };

         $.ajax({
             cache: false,
             type: "POST",
             dataType: 'json',
             contentType: 'application/json',
             data: JSON.stringify(option),
             url: '@(Url.Action("LogContentDetails", "ProductDetails"))',
                success: function (result) {
                    if (result.retult == true) {
                        //window.location = location.href;
                    } else {
                        //alert("Xin vui long dang nhap");
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    ///alert(thrownError);
                }
            });
    }
</script>

